package product

import (
	"context"
	// "fmt"
	"strconv"

	"mall/common/globalkey"
	"mall/common/utils/pointy"
	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/common/i18n"

	// "mall/service/backend/common/websocket"
	// "mall/service/product/rpc/productclient"

	// "github.com/sirupsen/logrus"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetPredefinedListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetPredefinedListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPredefinedListLogic {
	return &GetPredefinedListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPredefinedListLogic) GetPredefinedList() (resp *types.ProductPredefinedListResp, err error) {
	// _, err = l.svcCtx.ProductRpc.Diagnose(l.ctx, &productclient.DiagnoseReq{
	// 	Diagnose: 8,
	// })
	// if err != nil {
	// 	return nil, err
	// }

	// websocket.SendMessage(l.svcCtx.Config.Query.WebSocketChatUrl, "4", "10021")

	formDefault := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("status"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPending))),
		},
		{
			Key:   pointy.GetPointer("visibility"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPublic))),
		},
		{
			Key:   pointy.GetPointer("publicTime"),
			Value: pointy.GetPointer("3"),
		},
		{
			Key:   pointy.GetPointer("showStock"),
			Value: pointy.GetPointer("0"),
		},
		{
			Key:   pointy.GetPointer("permalinkTemplate"),
			Value: pointy.GetPointer(l.svcCtx.Config.NfsConf.SiteUrl + "/product/"),
		},
	}

	statusList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("publish"),
			Name:  pointy.GetPointer("在售"),
			Slug:  pointy.GetPointer("publish"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPublish))),
		},
		{
			Key:   pointy.GetPointer("draft"),
			Name:  pointy.GetPointer("草稿"),
			Slug:  pointy.GetPointer("draft"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusDraft))),
		},
		{
			Key:   pointy.GetPointer("future"),
			Name:  pointy.GetPointer("定时上架"),
			Slug:  pointy.GetPointer("future"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusFuture))),
		},
		{
			Key:   pointy.GetPointer("unavailable"),
			Name:  pointy.GetPointer("售罄"),
			Slug:  pointy.GetPointer("unavailable"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.ProductStatusUnavailable))),
		},
		{
			Key:   pointy.GetPointer("private"),
			Name:  pointy.GetPointer("仓库中"),
			Slug:  pointy.GetPointer("private"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPrivate))),
		},
		{
			Key:   pointy.GetPointer("pending"),
			Name:  pointy.GetPointer("待审核"),
			Slug:  pointy.GetPointer("pending"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPending))),
		},
		{
			Key:   pointy.GetPointer("rejected"),
			Name:  pointy.GetPointer("审核驳回"),
			Slug:  pointy.GetPointer("rejected"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusRejected))),
		},
		{
			Key:   pointy.GetPointer("trash"),
			Name:  pointy.GetPointer("回收站"),
			Slug:  pointy.GetPointer("trash"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusTrash))),
		},
	}

	metaKeyList := []*types.MetaInfo{
		{
			Key:  pointy.GetPointer("title"),
			Name: pointy.GetPointer("标题"),
			Slug: pointy.GetPointer("title"),
		},
		{
			Key:  pointy.GetPointer("keywords"),
			Name: pointy.GetPointer("关键词"),
			Slug: pointy.GetPointer("keywords"),
		},
		{
			Key:  pointy.GetPointer("description"),
			Name: pointy.GetPointer("描述"),
			Slug: pointy.GetPointer("description"),
		},
	}

	visibilityList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("on-sale"),
			Name:  pointy.GetPointer("在售"),
			Slug:  pointy.GetPointer("on-sale"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPublic))),
		},
		{
			Key:   pointy.GetPointer("sold-out"),
			Name:  pointy.GetPointer("已售罄"),
			Slug:  pointy.GetPointer("sold-out"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPasswordProtected))),
		},
		{
			Key:   pointy.GetPointer("in-stock"),
			Name:  pointy.GetPointer("仓库中"),
			Slug:  pointy.GetPointer("in-stock"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPrivate))),
		},
	}

	stickyList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("frontPage"),
			Name:  pointy.GetPointer("首页显示"),
			Slug:  pointy.GetPointer("frontPage"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.BlogStickyTypeFrontpage))),
		},
	}

	return &types.ProductPredefinedListResp{
		BaseDataInfo: types.BaseDataInfo{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
		},
		Data: types.ProductPredefinedListInfo{
			FormDefault:    formDefault,
			StatusList:     statusList,
			MetaKeyList:    metaKeyList,
			VisibilityList: visibilityList,
			StickyList:     stickyList,
		},
	}, nil
}
